// pages/vipQR/vipQR.js
let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: {},
    levelDate: '',
    pointDate: '',
    serverUrl: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      serverUrl: app.globalData.serverUrl
    })
    app.globalData.getCommonData().then(() => {
      let joinDate = app.globalData.clientInfo.joinDate.split(' ')[0]
      let joinYear = joinDate.split('-')[0]
      let joinMonth = joinDate.split('-')[1] - 1
      let joinDay = joinDate.split('-')[2]
      let joinObj1 = new Date(joinYear, joinMonth, joinDay)
      let joinObj2 = new Date(joinYear, joinMonth, joinDay)

      let levelValidity = +app.globalData.levelObj.levelValidity
      let pointValidity = +app.globalData.levelObj.pointValidity

      joinObj1.setMonth(joinObj1.getMonth() + levelValidity)
      let levelDate = joinObj1.toLocaleDateString()
      joinObj2.setMonth(joinObj2.getMonth() + pointValidity)
      let pointDate = joinObj2.toLocaleDateString()

      function transform(date){
        let data = date.split('/')
        return `${data[0]}年${data[1]}月${data[2]}日`
      }
      this.setData({
        info: app.globalData.clientInfo,
        levelDate: transform(levelDate),
        pointDate: transform(pointDate)
      })
    })

    app.globalData.post({
      url: '/shop/getShopInfo',
      data: {
        shopId: app.globalData.shopId
      },
      success: (data) => {
        this.setData({
          avatar: serverUrl + data.data.portrait
        })
      }
    })
  }, 

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})